#!/bin/bash
# **********************************************************
# * Author : liangliangSu
# * Email : sll917@hotmail.com
# * Create time : 2022-10-19 17:44
# * Filename : 10awk_数值运算.sh
# **********************************************************
#数值运算
awk -F: '$3 > 100' /etc/passwd   
echo '1 ----------------完美分割线------------------------'
awk -F: '$3 > 100 || $3 < 5' /etc/passwd 
echo '2 ----------------完美分割线------------------------'
awk -F: '$3+$4 > 200' /etc/passwd
echo '3 ----------------完美分割线------------------------'
awk -F: '/sll|mail/{print $3+10}' /etc/passwd               #第三个字段加10打印
echo '4 ----------------完美分割线------------------------'
awk -F: '/sll/{print $3-$4}' /etc/passwd                    #减法
echo '5 ----------------完美分割线------------------------'
awk -F: '/sll/{print $3*$4}' /etc/passwd                    #求乘积
echo '6 ----------------完美分割线------------------------'
awk '/MemFree/{print $2/1024}' /proc/meminfo                  #除法
echo '7 ----------------完美分割线------------------------'
awk '/MemFree/{print int($2/1024)}' /proc/meminfo             #取整
#4、运算符
#过滤第一列大于2的行:
echo '8+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'
awk '$1>2' test.txt    #命令
##输出
#3 Are you like awk
#This's a test
#10 There are orange,apple,mongo
#过滤第一列等于2的行:
echo '9+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'
awk '$1==2 {print $1,$3}' test.txt    #命令
##输出
#2 is
#过滤第一列大于2并且第二列等于’Are’的行:
echo '10+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'
awk '$1>2 && $2=="Are" {print $1,$2,$3}' test.txt    #命令
##输出
#3 Are you

